<template>
  <el-dialog :title="title"  center :visible.sync="open" v-if="open" width="1024px" append-to-body :close-on-click-modal="false">
    <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="140px">
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="交易流水号" prop="oriId">
            <el-input v-model="detailForm.oriId" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="CPG日期" prop="cpgdate">
            <el-date-picker
              v-model="detailForm.cpgdate"
              style="width: 100%"
              type="date"
              value-format="yyyyMMdd"
              :disabled="true"
            />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="工作日期" prop="workdate">
            <el-date-picker
              v-model="detailForm.workdate"
              style="width: 100%"
              type="date"
              value-format="yyyyMMdd"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="业务类型" prop="bizTypeCode">
            <el-select
              style="width: 100%"
              v-model="
                detailForm.bizTypeCode === null || detailForm.bizTypeCode === undefined
                  ? ''
                  : detailForm.bizTypeCode + '-' + detailForm.bizTypeCodeDesc
              "
              placeholder="业务类型"
              :disabled="true"
            ></el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="业务种类" prop="bizCtgyCode">
            <el-select
              style="width: 100%"
              v-model="
                detailForm.bizCtgyCode === null || detailForm.bizCtgyCode === undefined
                  ? ''
                  : detailForm.bizCtgyCode + '-' + detailForm.bizCtgyCodeDesc
              "
              placeholder="业务种类"
              :disabled="true"
            ></el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="业务回执期限" prop="bizRtDate">
            <el-date-picker
              v-model="detailForm.bizRtDate"
              style="width: 100%"
              type="date"
              value-format="yyyyMMdd"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="转发日期" prop="transmitDate">
            <el-date-picker
              style="width: 100%"
              v-model="detailForm.transmitDate"
              value-format="yyyyMMddHHmmss"
              type="datetime"
              :disabled="true"
            />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="扣款合同编号" prop="chargeNumber">
            <el-input v-model="detailForm.chargeNumber" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="收款人账号" prop="payeeActno">
            <el-input v-model="detailForm.payeeActno" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="收款人名称" prop="payeeName">
            <el-input v-model="detailForm.payeeName" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="收款行行号" prop="payeeBrno">
            <el-input v-model="detailForm.payeeBrno" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="收款行行名" prop="payeeBrname">
            <el-input v-model="detailForm.payeeBrname" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="收款人开户行行号" prop="payeeAccBrno">
            <el-input v-model="detailForm.payeeAccBrno" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="收款人开户行行名" prop="payeeAccBrname">
            <el-input v-model="detailForm.payeeAccBrname" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="付款人账号" prop="payerActno">
            <el-input v-model="detailForm.payerActno" :disabled="true" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="付款人名称" prop="payerName">
            <el-input v-model="detailForm.payerName" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="付款行行号" prop="payerBrno">
            <el-input v-model="detailForm.payerBrno" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="付款行行名" prop="payerBrname">
            <el-input v-model="detailForm.payerBrname" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="付款人开户行行号" prop="payerAccBrno">
            <el-input v-model="detailForm.payerAccBrno" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="付款人开户行名称" prop="payerAccBrname">
            <el-input v-model="detailForm.payerAccBrname" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="货币种类" prop="curcd">
            <el-input v-model="detailForm.curcd" :disabled="true" />
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="金额" prop="amount">
            <ht-amount-input v-model="detailForm.amount" placeholder="金额" :disable="true"></ht-amount-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="24">
          <el-form-item label="附言" prop="content">
            <el-input type="textarea" v-model="detailForm.content" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="non-stp类型" prop="nstpType">
            <el-select style="width: 100%" v-model="detailForm.nstpType" placeholder="non-stp类型" :disabled="true">
              <el-option
                v-for="dict in dictMap.NON_STP_TYPE"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="24">
          <el-form-item label="non-STP原因" prop="nstpRemarks">
            <el-input type="textarea" v-model="detailForm.nstpRemarks" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row type="flex">
        <el-col :span="12">
          <el-form-item label="记账标志" prop="cbflag">
            <el-select style="width: 100%" v-model="detailForm.cbflag" placeholder="记账标志">
              <el-option
                v-for="dict in dictMap.CBFLAG"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item label="业务回执状态" prop="bizRtStatus">
            <el-select
              style="width: 100%"
              v-model="detailForm.bizRtStatus"
              placeholder="业务回执状态"
              @change="bizRtStatusChange"
            >
              <el-option
                v-for="dict in dictMap.BIZRT_STATUS"
                :key="dict.value"
                :label="`${dict.value}-${dict.text}`"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <div v-if="this.detailForm.bizRtStatus === 'PR09'">
        <el-row type="flex">
          <el-col :span="8">
            <el-form-item label="业务拒绝处理码" prop="rejectCode">
              <el-input
                v-model="detailForm.rejectCode"
                placeholder="请输入业务拒绝处理码"
                @change="getbase('REJECTCODE')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-input v-model="detailForm.rejectCodeDesc" :disabled="true" />
          </el-col>
          <el-col :span="4">
            <el-row>
              <el-button
                type="primary"
                icon="el-icon-search"
                plain
                @click="openBasedataDialog('REJECTCODE')"
              >
                请选择
              </el-button>
            </el-row>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item label="业务拒绝原因" prop="rejectContent">
              <el-input type="textarea" v-model="detailForm.rejectContent" />
            </el-form-item>
          </el-col>
        </el-row>
      </div>
    </el-form>

    <div slot="footer" class="dialog-footer" align="center">
      <el-button type="primary" @click="submitForm" v-loading.fullscreen.lock="loading">提 交</el-button>
      <el-button type="primary" @click="cancel">关 闭</el-button>
    </div>

    <base-data-dialog ref="basedataDialog" @confirm="confirmData"></base-data-dialog>
  </el-dialog>
</template>
<script>
import BaseDataDialog from "@/views/components/BasedataDialog";
import HtAmountInput from "@/views/components/HtAmountInput";
import { getBasedata } from "@/api/cnaps/common/basedata";
import { bepsDebitNostroHdWkSave133 } from "@/api/cnaps/beps/baseHandWork/bepsDebitNostroHdWk";

export default {
  name: "BepsDebitNostroHdWkDetail133",
  components: { HtAmountInput, BaseDataDialog },
  props: {
    dictMap: {
      type: Object,
      default: () => {
        return {};
      },
    },
    detailForm: {
      type: Object,
      default: () => {
        return {};
      },
    },
  },
  data() {
    return {
      // 是否显示弹出层
      open: false,
      loading: false,
      title: "小额借记来账手工处理明细",
      rules: {
        cbflag: [{ required: true, message: "请输入记账标志", trigger: "blur" }],
        bizRtStatus: [{ required: true, message: "请输入业务回执状态", trigger: "blur" }],
        rejectContent: [{ max: 105, message: "最大位数为105位", trigger: "blur" }],
        rejectCode: [{ required: true, message: "请输入业务拒绝处理码", trigger: "blur" }],
        rejectCodeDesc: [{ required: true, message: "请输入业务拒绝处理码", trigger: "blur" }],
      },
    };
  },
  mounted() {},
  methods: {
    show() {
      this.open = true;
    },

    cancel() {
      this.open = false;
    },

    openBasedataDialog(dataType = "") {
      this.$refs.basedataDialog.show(dataType);
    },

    confirmData(fromFlag, row) {
      this.$set(this.detailForm, "rejectCode", row.dataValue);
      this.$set(this.detailForm, "rejectCodeDesc", row.dataDesc);
    },

    //回车获取basedata值
    getbase(dataType) {
      const dataValue = this.detailForm.rejectCode;
      getBasedata(dataType, dataValue)
        .then((response) => {
          if (response.code == "S" && response.result !== null && response.result !== undefined) {
            this.$set(this.detailForm, "rejectCode", response.result.dataValue);
            this.$set(this.detailForm, "rejectCodeDesc", response.result.dataDesc);
          } else {
            this.msgSuccess("找不到对应的字典项");
            this.$set(this.detailForm, "rejectCode", null);
            this.$set(this.detailForm, "rejectCodeDesc", null);
          }
        })
        .catch((err) => {
          this.$set(this.detailForm, "rejectCode", null);
          this.$set(this.detailForm, "rejectCodeDesc", null);
        });
    },

    bizRtStatusChange() {
      let bizRtStatus = this.detailForm.bizRtStatus;
      if (bizRtStatus === "PR02") {
        this.$set(this.detailForm, "rejectCode", "");
        this.$set(this.detailForm, "rejectCodeDesc", "");
        this.$set(this.detailForm, "rejectContent", "");
      }
    },

    submitForm: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          bepsDebitNostroHdWkSave133(this.detailForm)
            .then((response) => {
              this.msgSuccess("录入成功");
              this.open = false;
              this.$nextTick(() => {
                this.$parent.$refs.dataTable.doQuery(true);
              });
              this.loading = false;
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>
